var config = require("../../config");
import {
  Http
} from '../../http-d.js'
var http = new Http();
class UserModels {
  constructor() {
    this.ts_url = config.config.ts_url;
    // this.http = new Http();
  }

  login(){
    var that = this;
    wx.login({
      success:function(res){
        if(res.code){
          let code = res.code;
          wx.showLoading({
            title: '加载中...',
          })
          wx.request({
            url: that.ts_url + '/index/login/login',
            data: { 'code': code },
            header: {
              'content-type': 'application/x-www-form-urlencoded',
            },
            method: 'post',//方法也可以改成变量 传入
            success: function (res) {
              wx.hideLoading()
              var data = res.data.data;
              wx.setStorageSync('token', data.token);
              wx.setStorageSync('userinfo', data.userinfo);
            }
          })
        }
      }
    })
  }

  updateMobile(param,success){
    var url = '/index/user/editMobile';
    http.request(url, param, function (res) {
      success(res);
    })
  }
  getUserinfo(success){
    var url = '/index/user/myInfo';
    http.request(url,{},function(res){
      success(res);
    })
  }
  editInfo(param,success){
    var url = '/index/user/editInfo';
    http.request(url, param, function (res) {
      success(res);
    })
  }
  getBusinessCollect(success){
    var url = '/index/user/myCollection';
    http.request(url, {}, function (res) {
      success(res);
    })
  }
  becomingPartner(param,success){
    var url = '/index/user/becomingPartner';
    http.request(url, param, function (res) {
      success(res);
    })
  }
  changeInvite(param,success){
    var url = '/index/user/changeInvite';
    http.request(url, param, function (res) {
      success(res);
    })
  }
  submitPartner(param,success){
    var url = '/index/user/submitPartner';
    http.request(url, param, function (res) {
      success(res);
    })
  }
  setUpAddress(param, success) {
    var url = '/index/user/setUpAddress';
    http.request(url, param, function (res) {
        success(res);
    })
  }
}
export {
  UserModels
}